from bs4 import BeautifulSoup
import requests
import io
import sys

# 特殊字符会导致print报encode错误
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')
headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) \
    Chrome/54.0.2840.99 Safari/537.36"}
url = "http://www.apple.com/cn/ios/home/accessories"
response = requests.get(url, headers=headers)
content = response.content
htmlText = content.decode('utf8')
soup = BeautifulSoup(htmlText, 'lxml')
a_products = soup.select('.product')
print("Devices num is "+ str(len(a_products)))
for product in a_products:
    print(product.text)
